<?php
/**
 * Created by PhpStorm.
 * User: liu
 * Date: 2018/9/11
 * Time: 1:18
 */

namespace app\common\controller\font;


use app\common\exception\NotAllow;
use app\common\traits\CURD;
use think\Controller;
use think\Model;

/**
 * Class Base
 * @package app\common\controller\font
 * @property Model $model;
 */
class Base extends Controller
{
    protected $search_fields=null;
    protected $relation_search=null;
    protected $allow=['index','add','edit','remove'];
    use CURD;
    protected $model;

    public function initialize()
    {
        $action=$this->request->action();
        if(!in_array($action,$this->allow)){
            throw new NotAllow('你不能访问!!');
        }
    }

    public function index()
    {
        list($where,$offset,$limit,$order)=$this->buildParams();
        $rows=$this->model->where($where)
            ->order($order)
            ->paginate($limit,false,[
                'query'=>$where
            ]);
        return $this->fetch('',['rows'=>$rows]);
    }
}

